BEGIN {
	use FindBin;
	use lib "$FindBin::Bin";
}

use Pod::Usage;
use Getopt::Long;
use Wix::BuildManager;
use YAML::XS;

use strict;

my %opts;

GetOptions(
	\%opts,
	'help|h|?',
	'man'
) or pod2usage(-verbose => 1, exitval => 1);

if ($opts{help}) {
	pod2usage(-verbose => 1, exitval => 0);
}
elsif ($opts{man}) {
	pod2usage(-verbose => 2, exitval => 0);
}

my $config = shift;

unless ($config && -r $config) {
	pod2usage(-verbose => 1, -exitval => 1);
} 

eval {
	my $opts = YAML::XS::LoadFile($config);
	
	my $buildman = Wix::BuildManager->new($opts);
	$buildman->build();
} or do {
	pod2usage(-verbose => 0, -exitval => 2, -msg => $@);
};

__END__

=pod

=head1 NAME

wixbuild - A utility for creating simple Windows MSI installation packages

=head1 SYNOPSIS

wixbuild <YAML property build file>

=head1 OPTIONS

=over 8

=item B<--help>

Show basic usage information.

=item B<--man>

Show the full usage manual.

=back

=head1 DESCRIPTION

This application aims to simplify the process for building
Windows installer MSI packages using the WiX toolset.

The application reads a basic file containing various properties
describing the package and translates this into a .wxs source file
which is then used by WiX.

=head1 PROPERTIES

=over 8

=item B<NAME>

The name of the application

=item B<AUTHOR>

The manufacturer/author of the application

=item B<DESCRIPTION>

A short description of the application

=item B<VERSION>

The version number of the application (x.x.x.x)

=item B<FEATURES>

A list of the components to include in the package

=over 8

=item B<SRC>

The source directory containing files to include in the package

=item B<NOROOT>

Include just the files, do not recreate the enclosing directory

=item B<SHORTCUTS>

A list of shortcuts to applications in the package

=over 8

=item START

=over 8

=item <SRC>

=over 8

=item LINK

The path where the shortcut will be located 

=item NOROOT

Whether this shortcut should be included under a default application directory

=back

=back

=item DESKTOP

=over 8

=item <SRC>

=over 8

=item LINK

The path where the shortcut will be located 

=item NOROOT

Whether this shortcut should be included under a default application directory

=back

=back

=back

=item B<UI>

The dialog to use for the installer, one of:

=over 8

=item InstallDir

=item FeatureTree

=item Mondo

=back

=back

=head1 EXAMPLES

wixbuild.yml

  NAME: MyApp
  AUTHOR: My Name
  DESCRIPTION: A description of my application
  VERSION: 1.0.0.0
  FEATURES:
    FeatureOne:
      SRC: C:\Users\Me
    SHORTCUTS:
      START:
        C:\Users\Me\file.exe:
          LINK: File.exe
      DESKTOP:
      C:\Users\Me\file.exe:
          LINK: File.exe
          NOROOT: 1
  UI: InstallDir

=head1 AUTHOR

James Telford (james@tefd.co.uk)

=cut